﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Reflection;
using LibrarySystem;


namespace LibrarySystem
{
    public partial class FormMain : Form
    {
        ArrayList dailyAction = new ArrayList();  //日常管理操作列表
        ArrayList manageAction = new ArrayList();  //系统管理与维护操作列表
        int i = 1;
        private Form form = null;
        public FormMain()
        {
            InitializeComponent();
            //this.skinEngine1.SkinFile = "Emerald.ssk";//皮肤
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            this.Activate(); //激活当前窗体
            optionList.Select();//激活控件
            imageList1.ImageSize = new Size(10,40);
            optionList.StateImageList = imageList1;
            
            dailyAction.Add("借阅图书");
            dailyAction.Add("续借图书");
            dailyAction.Add("归还图书");
            dailyAction.Add("借阅查询");
            manageAction.Add("书刊信息维护");
            manageAction.Add("书刊信息查询");
            manageAction.Add("出版单位设置");
            manageAction.Add("书刊类别设置");
            manageAction.Add("读者信息维护");
            manageAction.Add("读者类型设置");
            manageAction.Add("用户信息管理");
            manageAction.Add("角色权限设置"); 
            //测试时使用静态信息，动态信息用下面的方式加入。
            //foreach (TuShuLeiXing tushuleixing in tslxm.GetBookType())
            //{
            //    lstBookClass.Add(tushuleixing.SName);
            //}
            Set();

            //this.lblUser.Text = UsersHelper.name;

            //InitQX();    //添加 菜单 项
        }
        private void Set()
        {
            optionList.Select();

            optionList.Dock = DockStyle.None;

            button1.Dock = DockStyle.Top;

            button2.Dock = DockStyle.Bottom;

            button2.SendToBack();
            //button3.Dock = DockStyle.Bottom;

            optionList.BringToFront();

            optionList.Dock = DockStyle.Bottom;
            optionList.Dock = DockStyle.Fill;

            optionList.Items.Clear();

            AddToLvShow(dailyAction, 0);
        }
        public void AddToLvShow(ArrayList arraylist, int i)
        {
            foreach (object obj in arraylist)
            {
                optionList.Items.Add(i.ToString(), obj.ToString(), i);
                i++;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            i = 1;
            Set();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            i = 2;
            optionList.Select();
            optionList.Dock = DockStyle.None;

            button2.Dock = DockStyle.Top;

            button1.SendToBack();
            button1.Dock = DockStyle.Top;

            optionList.Dock = DockStyle.Bottom;
            optionList.Dock = DockStyle.Fill;

            optionList.Items.Clear();
            AddToLvShow(manageAction, 0);
        }
        private void optionList_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ListViewItem lvi = optionList.FocusedItem;
            this.splitContainer1.Panel2.Controls.Clear();
            if (form != null)
            {
                form.Close();
            }
            if (i == 1)
            {
                switch(lvi.Index)
                {
                    case (0):
                        form = new BorrowForm();
                        break;
                    case (1):
                        form = new RenewForm();
                        break;
                    case (2):
                        form = new ReturnForm();
                        break;
                }
            }
            form.FormBorderStyle = FormBorderStyle.None; //隐藏子窗体边框（去除最小花，最大化，关闭等按钮）
            form.TopLevel = false; //指示子窗体非顶级窗体
            //this.panel2.Controls.Clear();
            this.panel2.Controls.Add(form);//将子窗体载入panel
            form.BringToFront();
            form.Location = new System.Drawing.Point(180, 0);
            form.Show();
            //if (form != null)
            //{
            //    form.Close();
            //}
            //if (this.i == 1 && lvi.Index == 3)
            //{
            //    FrmTushuChaXun frmt = new FrmTushuChaXun();
            //    frmt.ShowDialog();
            //}
            //else if (this.i == 1)
            //{
            //    switch (lvi.Index)
            //    {
            //        case (0):
            //            form = new FrmJieShu();
            //            break;
            //        case (1):
            //            form = new FrmTuShuXuJie();
            //            break;
            //        case (2):
            //            form = new FrmGuiHuan();
            //            break;
            //        //case (4):
            //        //    form = new FrmTushuChaXun();
            //        //    break;
            //    }
            //    form.FormBorderStyle = FormBorderStyle.None; //隐藏子窗体边框（去除最小花，最大化，关闭等按钮）
            //    form.TopLevel = false; //指示子窗体非顶级窗体
            //    //this.panel2.Controls.Clear();
            //    this.panel2.Controls.Add(form);//将子窗体载入panel
            //    form.BringToFront();
            //    form.Location = new System.Drawing.Point(180, 0);
            //    form.Show();
            //}
            //else
            //{
            //    //switch (lvi.Index)
            //    //{
            //    //    case (0):
            //    //        FrmBookInfoManager weih = new FrmBookInfoManager();
            //    //        weih.ShowDialog();
            //    //        break;
            //    //    case (1):
            //    //        TuShuChaXun.FrmTushuChaXun shuk = new TuShuChaXun.FrmTushuChaXun();
            //    //        shuk.ShowDialog();
            //    //        break;
            //    //    case (2):
            //    //        FrmPublishingSetting danWei = new FrmPublishingSetting();
            //    //        danWei.ShowDialog();
            //    //        break;
            //    //    case (3):
            //    //        FrmBookTypeSetting leib = new FrmBookTypeSetting();
            //    //        leib.ShowDialog();
            //    //        break;
            //    //    case (4):
            //    //        c duZhe = new c();
            //    //        duZhe.ShowDialog();
            //    //        break;
            //    //    case (5):
            //    //        FrmReadTypeSetting dzLeiXing = new FrmReadTypeSetting();
            //    //        dzLeiXing.ShowDialog();
            //    //        break;
            //    //    case (6):
            //    //        FrmYongHuDangAn yh = new FrmYongHuDangAn();
            //    //        yh.ShowDialog();
            //    //        break;
            //    //    case (7):
            //    //        FrmQuanXianMain qx = new FrmQuanXianMain();
            //    //        qx.ShowDialog();
            //    //        break;
            //    //}
            //}
            
        }
        ///// <summary>
        ///// 权限 菜单
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //private void InitQX()  //添加 菜单 项
        //{
        //    QuanXianManager qm = new QuanXianManager();

        //    List<QuanXian> lis = qm.LoginUsersQX();        //用户的权限

        //    QuanXianMenus("0", this.msMain.Items, lis); //自动生成角色　权限　菜单
        //}

        //private void QuanXianMenus(string pid, ToolStripItemCollection tsic, List<QuanXian> lis)//自动生成角色　权限　菜单
        //{
        //    foreach (QuanXian gt in lis)
        //    {
        //        if (gt.CKBianHao == pid)
        //        {
        //            ToolStripMenuItem tsmi = new ToolStripMenuItem();

        //            tsmi.Text = gt.QXMingChen;

        //            tsmi.Tag = gt.CKMingChen;  //窗体 名称 存入 Tag

        //            tsic.Add(tsmi);

        //            tsmi.Click += new EventHandler(tsmi_Click);  // 加载 菜单的事件

        //            QuanXianMenus(gt.QXBianHao, tsmi.DropDown.Items, lis);//递归  

        //        }

        //    }
        //}

        //void tsmi_Click(object sender, EventArgs e)
        //{
        //    ToolStripMenuItem tsmi = (ToolStripMenuItem)sender;

        //    string formName = Convert.ToString(tsmi.Tag);  //Tag 里面的 窗口 名称

        //    if (formName == "")
        //    {
        //        return;
        //    }

        //    //反射 找到 窗体
        //    Assembly ass = Assembly.GetExecutingAssembly();

        //    Form frm = ass.CreateInstance(formName, true) as Form;

        //    frm.ShowDialog();
        //}
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.timelb.Text = DateTime.Now.ToString("yy-MM-dd hh:mm:ss");//系统当前时间
        }

        private void logout_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            DialogResult dr = MessageBox.Show("是否要切换用户", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

            if (dr == DialogResult.OK)
            {
                Application.Restart();
            }
        }

        private void exit_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            DialogResult dr = MessageBox.Show("是否要退出系统？", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

            if (dr == DialogResult.Cancel)
            {
                return;
            }
            else
            {
                //退出
                Application.Exit();
            }
        }

    }
}
